package com.guigu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.BusinessesService;
import com.guigu.OrderService;
import com.guigu.pojo.Businesses;
import com.guigu.pojo.Order;
import com.guigu.utils.NumberUtils;
import com.guigu.utils.NumberUtils1;
import com.guigu.vo.Pojo;
import com.guigu.vo.Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RequestMapping("Order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private BusinessesService businessesService;
    @Autowired
    private NumberUtils1 numberUtils1;
    @Autowired
    private NumberUtils numberUtils;
    //分页查询个人订单
    @RequestMapping("/getPage")
    public Pojo<Order> getPage(Integer pageNum, Integer pageSize,@RequestBody Vo vo) {
        System.out.println(vo);
        System.out.println(pageNum);
        System.out.println(pageSize);
        Pojo<Order> pojo = orderService.getPage(pageNum,pageSize,vo);
        System.out.println(pojo);
        return pojo;
    }
    //查询商户
    @RequestMapping("/selectById")
    public Businesses selectById(int userId) {
        System.out.println(userId);
         Businesses businesses = orderService.selectById(userId);
        System.out.println(businesses);
        return businesses;
    }
    //根据id修改
    @PutMapping("/updateById")
    public String updateById(@RequestBody Businesses businesses) {
        System.out.println("999"+businesses);
        Businesses businesses1=new Businesses();
        businesses1.setIsBusiness(businesses.getIsBusiness());
        QueryWrapper<Businesses> wrapper = new QueryWrapper<>();
        wrapper.eq("id6", businesses.getId());
        boolean b = businessesService.update(businesses1, wrapper);
        if (b)
            return "ok";
        return "no";
    }


    //新增订单
    @PostMapping("/insert")
    public Order insert(@RequestBody Order order) {
        //订单编号
        String orderId = numberUtils.setOrderId("100");
        order.setOrderId(orderId);
        //订单状态（2为待付款）
        order.setStatus(2);
       int b = orderService.insert(order);
        if (b>0){
            Order order1 = orderService.One(orderId);
            return order1;
        }
        return null;
    }
    //修改
    @PutMapping("/update")
    public String update(@RequestBody Order order) {
        int b = orderService.update(order);
        if (b>0)
            return "ok";
        return "no";
    }

}
